package com.gitee.huxing.courese.core;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Description:
 * @ProjectName: JavaCourse
 * @Package: com.gitee.huxing.courese.core
 * @ClassName: KmqBroker
 * @Author: huxing
 * @DateTime: 2021-11-07 4:03 下午
 */
public final class KmqBroker {

    public static final int CAPACITY = 10000;

    private final Map<String, Kmq> kmqMap = new ConcurrentHashMap<>(64);

    public void createTopic(String name){
        kmqMap.putIfAbsent(name, new Kmq(name, CAPACITY));
    }

    public Kmq findKmq(String topic){
        return this.kmqMap.get(topic);
    }

    public KmqConsumer createConsumer(){
        // 创建一个消费者对象
        KmqConsumer consumer = new KmqConsumer(this);
        // 保存消费者对象的hash 默认起始消费位置为0
        // 返回消费对象
        return consumer;
    }

    public KmqProducer createProducer(){
        return new KmqProducer(this);
    }
}
